﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ThermalEquipmentDesign.Model.CoolerWet
{
    public class CoolerWetModel
    {
        public CoolerWetResult result = new CoolerWetResult();
        public CoolerWet coolerwet;

        /// <summary>
        /// Calculate Air Flow
        /// </summary>
        /// <returns>Air Flow</returns>
        private double AirFlow()
        {
            double m = coolerwet.dbCapacity / (coolerwet.dbAirEntanpiIn - coolerwet.dbAirEntanpiOut);
            return Math.Round(m,2);
        }

        /// <summary>
        /// Calculate Basal Area
        /// </summary>
        /// <returns>Basal Area</returns>
        private double BasalArea()
        {
            double m = coolerwet.dbCapacity / (coolerwet.dbAirEntanpiIn - coolerwet.dbAirEntanpiOut);
            double F = m / 2.5;
            return F;
        }

        /// <summary>
        /// Calculate Moisture Condensation
        /// </summary>
        /// <returns>Moisture Condensation</returns>
        private double MoistureCondensation()
        {
            double m = coolerwet.dbCapacity / (coolerwet.dbAirEntanpiIn - coolerwet.dbAirEntanpiOut);
            double W = m * (coolerwet.dbAirVaporIn - coolerwet.dbAirVaporOut);
            return Math.Round(W,4);
        }

        /// <summary>
        /// Calculate Total Spray
        /// </summary>
        /// <returns>Total Spray</returns>
        private double TotalSpray()
        {
            double m = coolerwet.dbCapacity / (coolerwet.dbAirEntanpiIn - coolerwet.dbAirEntanpiOut);
            double F = m / 2.5;
            double n = 3 * 14 * F;
            return Math.Round(n,0);
        }

        /// <summary>
        /// Calculate Water Spray
        /// </summary>
        /// <returns>Water Spray</returns>
        private double WaterSpray()
        {
            double m = coolerwet.dbCapacity / (coolerwet.dbAirEntanpiIn - coolerwet.dbAirEntanpiOut);
            double mw = 3.5 * m;
            return Math.Round(mw, 2);
        }

        /// <summary>
        /// Calculate Water Each Spray
        /// </summary>
        /// <returns>Water Each Spray</returns>
        private double WaterEachSpray()
        {
            double m = coolerwet.dbCapacity / (coolerwet.dbAirEntanpiIn - coolerwet.dbAirEntanpiOut);
            double mw = 3.5 * m;
            double F = m / 2.5;
            double n = 3 * 14 * F;
            double mwl = mw / n;
            return Math.Round(mwl,3);
        }

        /// <summary>
        /// Calculate Cooler Wet
        /// </summary>
        /// /// <param name="con">CoolerWet object</param>
        /// <returns>CoolerWetResult object</returns>
        public CoolerWetResult ImplementCalculation(CoolerWet cw)
        {
            coolerwet = cw;
            result.dbAirFlow = AirFlow();
            result.dbBasalArea = BasalArea();
            result.dbMoistureCondensation = MoistureCondensation();
            result.dbTotalSpray = TotalSpray();
            result.dbWaterEachSpray = WaterEachSpray();
            result.dbWaterSpray = WaterSpray();
            return result;
        }
    }
}
